--- title: Interactive Plots keywords: fastai sidebar: home_sidebar summary: "We use plotly for interactive plotting. Data for plotly is obtained using `create_rgb_lines`. Here `elements` are replaced by `ions` because main purpose of these plots is to create an interactive application where everything could be changed dynamically." description: "We use plotly for interactive plotting. Data for plotly is obtained using `create_rgb_lines`. Here `elements` are replaced by `ions` because main purpose of these plots is to create an interactive application where everything could be changed dynamically." nb_path: "InteractivePlots.ipynb" ---
This is a simple example of using plotly. It is slower than matplotlib but interactive.
import os
import pivotpy as pp
os.chdir('E:/Research/graphene_example/ISPIN_2/bands')
fig=pp.plotly_rgb_lines(mode='lines',elim=[-10,10],orbs=[[0],[1],[2,3]],labels=['s','p<sub>z</sub>','p<sub>x</sub>+p<sub>y</sub>'], xt_indices=[0,30,60,-1],xt_labels=['Γ','M','K','Γ'],E_Fermi=-2.7735)
pp.plotly_to_html(fig)
plotly_rgb_lines make_subplots object by getting data=plotly_rgb_lines().data and layout=plotly_rgb_lines().layout objects. See example below: import plotly.graph_objects as go
from IPython.display import HTML
import pivotpy.i_plots as ips
import os
from plotly.subplots import make_subplots
os.chdir('E:/Research/graphene_example/ISPIN_1/bands')
inds=[0,30,60,-1]
lbs=['Γ','M','K','Γ']
kargs=dict(mode='markers',elim=[-10,10],xt_indices=inds,xt_labels=lbs)
fig5=go.FigureWidget(make_subplots(rows=2, cols=2,shared_yaxes=True,shared_xaxes=True,
horizontal_spacing=0.08,
vertical_spacing=0.1,
subplot_titles=['s','pz','py','s,p,d'],
column_widths=[1,2],
row_heights=[1,2],
y_title='Energy (eV)'
))
[fig5.add_trace(trace,row=1,col=1) for trace in ips.plotly_rgb_lines(orbs=[0,[],[]],**kargs).data]
[fig5.add_trace(trace,row=1,col=2) for trace in ips.plotly_rgb_lines(orbs=[[],[1],[]],**kargs).data]
[fig5.add_trace(trace,row=2,col=1) for trace in ips.plotly_rgb_lines(orbs=[[],[],[2]],**kargs).data]
last=ips.plotly_rgb_lines(**kargs)
[fig5.add_trace(trace,row=2,col=2) for trace in last.data]
fig5.update_layout(width=600,height=400,font=last.layout.font,margin=dict(r=10,l=10,t=40,b=40))
fig5.update_xaxes(last.layout.xaxis)
last.layout.yaxis.title=''
fig5.update_yaxes(last.layout.yaxis)
HTML(fig5.to_html())
Click on gridplot.html to see the plot generated from above code.
collect_dos in Plotly quick_dos_lines is created in plotly below. Plotly will reduce number of parameters and you are able to tweek those parameters interactively in graph.import pivotpy as pp
fig=pp.plotly_dos_lines(path_evr='E:/Research/graphene_example/ISPIN_2/dos/vasprun.xml',vertical=False,fill_area=True,elements=[[0],[1],[]],orbs=[0,1,[2,3]],labels=['C1-s','C2-p<sub>z</sub>','None-p<sub>x</sub>+p<sub>y</sub>'],figsize=(700,550))
pp.plotly_to_html(fig)